<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\OrderAppoint;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class OrderAppointController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new OrderAppoint(['user','teacher']), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('user.name','咨询人');
            $grid->column('teacher.name','咨询师');
            $grid->column('day');
            $grid->column('appoint_time');
            $grid->column('consult_type')->using([1=>'心理',2=>'占卜',3=>'倾听'])->filter();
            $grid->column('consult_way')->using([1=>'文字',2=>'语音',3=>'视频']);
            $grid->column('begin_time');
            $grid->column('end_time');
            $grid->column('buy_time');
            $grid->column('price');
            $grid->column('status')->using([0=>'已下单',1=>'已下单',2=>'进行中',3=>'取消',4=>'完成',5=>'已评价'])->filter();
            $grid->column('grade');
            $grid->column('duration_time');
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('user.name','咨询人');
                $filter->equal('teacher.name','咨询师');

            });
            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->disableCreateButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new OrderAppoint(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('appoint_id');
            $show->field('day');
            $show->field('appoint_time');
            $show->field('consult_type');
            $show->field('begin_time');
            $show->field('end_time');
            $show->field('buy_time');
            $show->field('comment');
            $show->field('status');
            $show->field('grade');
            $show->field('duration_time');
            $show->field('created_at');
            $show->field('updated_at');
            $show->disableDeleteButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new OrderAppoint(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('appoint_id');
            $form->text('day');
            $form->text('appoint_time');
            $form->text('consult_type');
            $form->text('begin_time');
            $form->text('end_time');
            $form->text('buy_time');
            $form->text('comment');
            $form->text('status');
            $form->text('grade');
            $form->text('duration_time');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
